﻿using AutoMapper; //AutoMapper
using PcProject.Application.Service.AutoMapper;
using PcProject.Domain.IRepository;
using PcProject.Domain.Models.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using PcProject.Infrastructure.Repository;

namespace PcProject.Application.Service.Products
{
    /// <summary>
    /// 商品模块
    /// </summary>
    public class SpecificaService : ISpecificaService
    {
        /// <summary>
        /// 构造函数依赖注入
        /// </summary>
        private ISpecificaRepository _productRepository;
        private IMapper _mapper;
        /// <summary>
        /// 函数依赖注入
        /// </summary>
        /// <param name="productRepository"></param>
        /// <param name="mapper"></param>
        public SpecificaService(ISpecificaRepository productRepository,IMapper mapper)
        {
            _productRepository = productRepository;
            _mapper = mapper;
        }


        /// <summary>
        /// 显示商品规格
        /// </summary>
        /// <returns></returns>
        public List<Specification> GetSpecifications()
        {
            return _productRepository.GetSpecifications();
        }

        /// <summary>
        /// 添加商品规格
        /// </summary>
        /// <param name="obj">参数</param>
        /// <returns></returns>
        public async Task<int> AddSpecAsyn(Specification obj)
        {
            Specification a = _mapper.Map<Specification>(obj);
            return await _productRepository.AddSpecAsyn(a);
        }

        /// <summary>
        /// 删除商品规格
        /// </summary>
        /// <param name="id">主键</param>
        /// <returns></returns>
        public async Task<int> DeleSpecAsync(int id)
        {
            return await _productRepository.DeleSpecAsync(id);
        }

        /// <summary>
        /// 反填规格
        /// </summary>
        /// <param name="id">主键</param>
        /// <returns></returns>
        public Specification FillSpecAsync(int id)
        {
            return _productRepository.FillSpecAsync(id);
        }

        /// <summary>
        /// 修改规格
        /// </summary>
        /// <param name="obj">参数</param>
        /// <returns></returns>
        public async Task<int> UptSpecAsync(Specification obj)
        {
            Specification a = _mapper.Map<Specification>(obj);
            return await _productRepository.UptSpecAsync(a);
        }

    }
}
